class Solution
{
public:
    int sumDistance(vector<int> &nums, string s, int d)
    {
        int n = nums.size();
        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'L')
            {
                nums[i] -= d;
            }
            else
            {
                nums[i] += d;
            }
        }
        sort(nums.begin(), nums.end());
        long long prefixSum = nums[0];
        long long result = 0;
        for (long long i = 1; i < n; ++i)
        {
            result += i * nums[i] - prefixSum;
            result %= 1000000007;
            prefixSum += nums[i];
        }
        return result;
    }
};